/**
 * @description **验证字符串长度范围**
 * @param {String} value
 * @param {Number} minLength 最小长度
 * @param {Number} maxLength 最大长度
 * @returns Boolean
 * @example
 *
 * ```js
 * let str='ab'
 * lengthRange(str,1,2)
 * ```
 * 
 */
const lengthRange=(value,minLength,maxLength)=>{
    return Boolean(value.length >= minLength && value.length <= maxLength);
}


/**
 * @description **验证字符串是否以字母开头**
 * @param {String} value
 * @returns Boolean
 */
const letterBegin=(value)=>{
    return /^[A-z]/.test(value);
}


/**
 * @description **验证字符串是否为纯数字**
 * @param {String} value
 * @returns Boolean
 */
const pureNum=value=>{
    return /^[0-9]*$/.test(value);
}


/**
 * @description **验证大陆邮政编码**
 * @param {String} value
 * @returns Boolean
 */
const isMail=value=>{
    return /^[1-9][0-9]{5}$/.test(value.toString());
}


/**
 * @description **验证二代身份证；共18位，最后一位可为x**
 * @param {String} value
 * @returns Boolean
 */
const isIdCard=value=>{
    return /^[1-9][0-9]{5}(18|19|(2[0-9]))[0-9]{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)[0-9]{3}[0-9Xx]$/.test(value);
}


/**
 * @description **验证是否为网址**
 * @param {String} value
 * @returns Boolean
 */
const isURL=value=>{
    return /^(https:\/\/|http:\/\/|ftp:\/\/|rtsp:\/\/|mms:\/\/)?[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/.test(value);
}


/**
 * @description **验证QQ号；非0开头的5~13位整数**
 * @param {String} value
 * @returns Boolean
 */
const isQQ=value=>{
    return /^[1-9][0-9]{4,12}$/.test(value.toString());
}



/**
 * @description **验证电子邮箱**
 * @param {String} value
 * @returns Boolean
 */
const isEmail=value=>{
    return /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test(value);
}


/**
 * @description **验证手机号**
 * @param {String} value
 * @returns Boolean
 */
const isPhone=value=>{
    return /^1[3,4,5,6,7,8,9][0-9]{9}$/.test(value.toString());
}


/**
 * @description **验证电话号码**
 * @param {String} value
 * @returns Boolean
 */
const isTel=value=>{
    return /^([0-9]{3,4})?[0-9]{7,8}$|^([0-9]{3,4}-)?[0-9]{7,8}$/.test(value);
}

export {lengthRange,letterBegin,pureNum,isMail,isIdCard,isURL,isQQ,isEmail,isPhone,isTel}